package com.aubrey.threadDemo.create;

import java.util.concurrent.atomic.AtomicInteger;

public class VolatileDemo {
	public volatile static  int start =0;
	public AtomicInteger atoStart = new AtomicInteger(0);
	/**
	 * 添加synchronized修饰可以同步
	 * lock可以同步
	 * atmoicinteger 可以同步
	 */
	public void increase() {
		start++;
		atoStart.getAndIncrement();
    }
	
	
	public static void main(String[] args) {
		VolatileDemo vd = new VolatileDemo();
		for (int i = 0; i < 10; i++) {
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					for (int j = 0; j < 1000; j++) {
//						vd.increase();
						start++;
					}
					
				}
			}).start();
		}
		
		while(Thread.activeCount() > 1)Thread.yield();
		System.out.println(vd.start+":" + vd.atoStart);
	}

}
